/*******************************************************************************
  * Copyright(c) 2023 Levetop Semiconductor Co.,Led. All rights reserved.
  * @file     bsp.h
  * @author   UartTFT Application Team
  * @version  V0.0.1
  * @date     2023-01-04
  * @brief    This file contains the functions prototypes for the UartTFT
  *           Application display firmware.
 ********************************************************************************/

#ifndef _BSP_H
#define _BSP_H

#include "uart.h"
#include "rtc.h"
#include "qr_encode.h"
#include "module_select.h"
#include "w25qxx.h"
#include "w25n01.h"
#include "GBK.h"
#include "pit32_drv.h"

#define MAIN_BUFF		0
#define LAY_BUFF1		0
#define LAY_BUFF2		0
#define LAY_BUFF3		0
#define LAY_BUFF4		0
#define LAY_BUFF5		0
#define LAY_BUFF6		0
#define LAY_BUFF7		0
#define LAY_BUFF8		0
#define LAY_BUFF9		0
#define LAY_BUFF10		0	
#define LAY_BUFF11		0
#define LAY_BUFF12		0
#define LAY_BUFF15		0
#define slideMune_BUFF	0

extern uint8_t Ye_Mian_num;
extern uint16_t send500_time;
extern int pic_flagA;  
extern int pic_flagB;  
extern int pic_flagC;

#define Cup_sAddr 0x08070800   //450K
#define flh_sAddr 0x08073000   //460K
#define Ye_Mian_sAddr flh_sAddr+0 		//ҳ�����
#define DangWei1_sAddr flh_sAddr+1 		//��λһ���� Q��
#define DangWei2_sAddr flh_sAddr+2 		//��λһ���� F��
#define DangWei3_sAddr flh_sAddr+3 		//��λһ���� R��
#define WR_SIZE 4

extern uint32_t Display_Layer;
extern uint8_t Flash_type;

/*ModBus operating variables*/
extern uint16_t Cnt_ModbusTX;
extern uint16_t Sum_ModbusTX;

/*picture information*/
extern uint16_t pic_id;
extern uint16_t pic_id_temp;
extern uint32_t pic_add;
extern uint16_t pic_w;
extern uint16_t pic_h;
extern uint32_t pic_len;
extern uint8_t pic_flag;

/*Variable space*/
extern uint8_t *var;
// extern uint8_t var[];
extern uint8_t var_temp[];
extern uint8_t config_buff[];
extern uint16_t data_w;
extern uint8_t Display_buff[STRLEN_SIZE];
extern uint8_t Display_buff_temp[];

/*backlight information*/
extern uint16_t gDutyBuf[];
//extern uint8_t gDutyflag;
extern uint8_t Auto_Backlight;
//extern uint8_t Backlight_On;
//extern uint8_t Backlight_Off;
//extern uint16_t Backlight_time;
extern uint32_t Backlight_count;
extern uint8_t Backlight_flag;
//extern uint8_t Backlight_first_touch;
extern uint8_t Backlight_touch;

/*configuration parameter variable*/
extern uint8_t buzzer;
extern uint16_t Start_page;
extern uint8_t SCI_C0;
extern uint8_t SCI_C1;
extern uint8_t CRC_Enable_Flag;
extern uint8_t CRC_Feedback_Flag;
extern uint8_t parity_flag;
extern uint8_t Screen_DIR;
extern uint8_t TFT_bitcolor;
extern uint8_t multi_language;
extern uint8_t multi_language_count;
extern uint8_t UI_update;

/*touch public*/
extern uint8_t button_Press_flag;
extern uint8_t buzzer_start;
extern uint8_t buzzer_10ms_count;
extern uint8_t Button_Key_Code_Flag;
extern uint16_t Button_Key_Code;

/*volume*/
extern uint8_t wav_reduce_para;

extern uint16_t gEncoder_addr[];
extern uint8_t gEncoder_num;
extern uint8_t gEncoderFlag;

extern uint16_t Check_box_add;
extern uint8_t Check_box_flag;
extern uint8_t Encoder_num;
extern uint8_t Encoder_read_Flag, Encoder_Freetime;
extern uint8_t knob_dir, SW_flag, Enc0, Enc1, SW_flag4, key_time;
extern uint16_t Encoder_time;
extern uint8_t Double_click_interval;
extern uint8_t Long_press, Encoder_type;

extern uint8_t pdata_D_num;

extern uint8_t Count_sum;
extern uint8_t Count_flag;
extern uint8_t Record_count;
extern uint16_t Count_reg[8]; 
extern uint8_t Count_reg_num;

extern uint8_t data_D_num;
extern uint16_t data_D_w[DATA_WLEN_SIZE];
extern uint16_t data_w;


extern uint16_t pdata_D_w[DATA_WLEN_SIZE];

extern uint8_t knob_flag;

extern uint16_t Curve_buff[CURVE_SIZE][1024];
extern uint16_t Curve_count[CURVE_SIZE];
extern uint8_t curve_update_flag[CURVE_SIZE];

extern uint8_t lt_screen_dir;

//----------------others module---------------------
void BackLight_control(void); 		// backlight
void LT_LCD_screen_dir(uint8_t dir); // screen_dir
void LT_TP_dir(void);
void LT_LCD_init_dir(uint8_t dir);
void touch_buzzer(void); 			// touch buzzer
void APP_reset(uint32_t appxaddr);

uint32_t GetCrc32(uint8_t *InStr,uint32_t len,uint32_t value);

void LT_ReceiveCmd(uint8_t *buf); // communication
void LT_ModBus_REG_Cmd(void);
void LT_IIC_REG_Cmd(void);
void LT_Hid_ReceiveCmd(uint8_t *buf);

void Var_AddrRemapping(uint16_t *addr);
void Var_AddrToReg(uint8_t *buf);
uint8_t CoordinateChangeToBox(int16_t *x, int16_t *y, int16_t *w, int16_t *h, uint8_t alignment, _PICINFO pic, uint8_t mix);

void reg_operation(uint16_t addr); // reg operation

//-----------------------------------------------------Function display-----------------------------------------------
/*Page display*/
void Display_page(uint16_t id);

/*pop-up notification*/
void Display_pop_up(uint16_t id, uint16_t x, uint16_t y);

/*icon*/
void Display_Icon(uint16_t id, uint16_t x, uint16_t y, uint8_t Display_mode);
void icon_display(uint8_t type, uint8_t *buff);

/*Bit variable control*/
void bit_control(uint8_t type, uint8_t *buff);

/*gif*/
void gif_display(uint8_t type, uint8_t *buff);
void show_gif(void);
uint8_t LT_ShowGifPicture(uint8_t num);

/*digital clock*/
// uint8_t Display_RTC(RTC_Info *gRTC,uint8_t status);
void RTC_display(uint8_t type, uint8_t *buff);
void show_RTC(void);

/* analog clock */
// uint8_t Display_Clock(uint8_t num,uint8_t status);
void Clock_display(uint8_t type, uint8_t *buff);
void show_Clock(void);

/*time counter*/
void count_display(uint8_t type, uint8_t *buff);
uint8_t Display_Count(uint8_t i);
void show_Count(void);
void Saving_counting_parameters(void);

/****Variable_Count display****/
void Check_Var_Count(void);
void Variable_Count(uint8_t type, uint8_t *buff);

/*QRcode*/
void qr_code(uint8_t type, uint8_t *buff);

/*progress bar*/
void progress_bar(uint8_t type, uint8_t *buff);

/*ring progress bar*/
void Circular_progress_bar(uint8_t type, uint8_t *buff);

/**********pointer************/
void Pointer_display(uint8_t type, uint8_t *buff);
uint8_t Run_Pointer(uint8_t num);
void Check_Pointer(void);

/*curve*/
//void Real_time_curve_display_static(Curve_Info curve);
void Real_time_curve_display_dynamic(uint8_t group);
void Curve_display(uint8_t type, uint8_t *buff);
void Display_Curve(void);

/*encoder*/
void Display_encoder(uint8_t *buff, uint8_t type);
void get_encoder(uint8_t type, uint8_t *buff, uint16_t addr);
void encoder(void);

/*picture data display*/
void pic_date_display(uint8_t type, uint8_t *buff);

/*data display*/
void data_display(uint8_t type, uint8_t *buff);

/*Text scrolling*/
void text_scroll(uint8_t type, uint8_t *buff);
uint8_t text_scroll_Once(uint8_t num);
void scroll_text(void);

/*text display*/
void text_display(uint8_t type, uint8_t *buff);


//-----------------------------------------------------Function with Touch-----------------------------------------------
/*basic touch function*/
void Basic_touch(void);

/*variable adjustment with touch*/
void Adj_touch(void);
void VarKey_touch(void);

/*pop-up window*/
void pop_up_touch(void);

/*sliding gesture*/
void Gesture_touch(void);

/*progress bar with touch*/
void Disp_slide(uint8_t i);
void Progress_bar_sliding(void);

/*ring progress bar with touch*/
void DL_RingSld(uint8_t num);
void RingSld_Display(uint8_t num, uint16_t angle);
void RingSld_touch(void);

/*sliding menu*/
void slideMune(void);
void dp_menu(uint8_t num);
void DL_menu(uint8_t num);

/*data keyboard*/
void input_display(void);
uint8_t buff_to_var(uint8_t *buff);
void data_input(void);

/*ASCII keyboard*/
void Ascii_input(void);

/*GBK keyboard*/
void GBK_input(void);



void APP(uint32_t appxaddr);


uint16_t LT_Print_zk_Font(
uint16_t encode // encoding type     0:GB2312  1:GBK  2:BIG5  3:UNICODE  4:ASCII  6:UNICODE
	,
	uint32_t FlashAddr // Font source address(exSpiFlash)
	,
	uint32_t ShowAddr // Displays the address of the layer
	,
	uint16_t width // Display the width of the layer
	,
	uint8_t W_Size // font width
	,
	uint8_t H_Size // font height
	,
	uint8_t Alignment // Alignment
	,
	uint32_t FontColor // The foreground color of the font
	,
	uint32_t BackColor // The background color of the font
	,
	uint8_t enbackcolor // Background color enable, 0:disable  1:enable
	,
	uint8_t mix // mix mode, 0:with fullscreen interface   1:with specific pictures(Text box needs to be fully included)
	,
	_PICINFO mixpic // mix picture info
	,
	uint8_t text_mode // text display mode: 0:txt  1:encryption use '*' (0x2A)
	,
	uint16_t Xs // Text box start x position
	,
	uint16_t Ys // Text box start Y position
	,
	uint16_t Xe // Text box end x position
	,
	uint16_t Ye // Text box end y position
	,
	uint8_t dis_x // The interval between two adjacent fonts on the x-axis
	,
	uint8_t dis_y // The interval between two adjacent fonts on the y-axis
	,
	uint8_t *c // Address of text
	,
	uint16_t len_max // max lenght of text
);

uint16_t LT_Print_zk_Font_BUFF(
	uint16_t encode // encoding type     0:GB2312  1:GBK  2:BIG5  3:UNICODE  4:ASCII  6:UNICODE
	,
	uint32_t FlashAddr // Font source address(exSpiFlash)
	,
	uint32_t ShowAddr // Displays the address of the layer
	,
	uint16_t width // Display the width of the layer
	,
	uint8_t W_Size // font width
	,
	uint8_t H_Size // font height
	,
	uint8_t Alignment // Alignment
	,
	uint32_t FontColor // The foreground color of the font
	,
	uint32_t BackColor // The background color of the font
	,
	uint8_t enbackcolor // Background color enable, 0:disable  1:enable
	//,uint16_t mix                 // mix mode, 0:with fullscreen interface   1:with specific pictures(Text box needs to be fully included)
	//,_PICINFO mixpic                    // mix picture info
	,
	uint16_t buf_w // width of buffer
	,
	uint16_t buf_h // height of buffer
	,
	uint8_t *buf // address of buffer
	,
	uint16_t buf_x // start x of buffer
	,
	uint16_t buf_y // start y of buffer
	,
	uint8_t dis_x // The interval between two adjacent fonts on the x-axis
	,
	uint8_t dis_y // The interval between two adjacent fonts on the y-axis
	,
	uint8_t *c // Address of text
	,
	uint16_t len_max // max lenght of text
);

uint16_t LT_Print_zk_Font_Scroll(
	uint16_t encode // encoding type     0:GB2312  1:GBK  2:BIG5  3:UNICODE  4:ASCII  6:UNICODE
	,
	uint32_t FlashAddr // Font source address(exSpiFlash)
	,
	uint32_t ShowAddr // Displays the address of the layer
	,
	uint16_t width // Display the width of the layer
	,
	uint8_t W_Size //  font width
	,
	uint8_t H_Size // font height
	,
	uint8_t Alignment // Alignment
	,
	uint32_t FontColor // The foreground color of the font
	,
	uint32_t BackColor // The background color of the font
	,
	uint8_t enbackcolor // Background color enable, 0:disable  1:enable
	,
	uint8_t mix // mix mode, 0:with fullscreen interface   1:with specific pictures(Text box needs to be fully included)
	,
	_PICINFO mixpic // mix picture info
	,
	uint16_t Xs // Text box start x position
	,
	uint16_t Ys // Text box start Y position
	,
	uint16_t Xe // Text box end x position
	,
	uint16_t Ye // Text box end y position
	,
	uint8_t dis_x // The interval between two adjacent fonts on the x-axis
	,
	uint8_t dis_y // The interval between two adjacent fonts on the y-axis
	,
	uint8_t *c // Address of text
	,
	uint16_t len_max // max lenght of text
	,
	uint8_t num // Scroll_num
	,
	uint16_t x_off // x offset
);

//-------------------------------------Variable area of function----------------------------------------------------------------------------
/*gif*/
extern uint8_t Gif_num;
extern uint8_t Gif_flag;
typedef struct
{
	uint32_t addr;
	uint32_t total;
	uint16_t p_add;
	uint16_t x; // x,y of screen
	uint16_t y;
	uint16_t w;
	uint16_t h;
	uint16_t gif_id;
	uint16_t reset_En; // 0x0000:When stopping, the start value of the animation icon is not reset (the animation icon displays from any value between ICON_Start and ICON_End).
					   // 0x0001:When stopping, the start value of the animation icon will be reset (the animation icon display will be fixed from ICON_Start).
	uint8_t t_d; // Frame time interval
	uint8_t t_c; // Record time
	uint8_t p_c;
	uint16_t V_stop;  // The fixed icon is displayed when the variable is at this value.
	uint16_t V_start; // The animated icon is automatically displayed when the variable is this value.
	uint16_t V_once;  // play only once
	uint8_t mode;
	uint8_t flag;
	uint16_t var_addr[8];
	uint16_t var[8];
	uint8_t on_gif;
} Gif_Info;
extern Gif_Info gGif_Info[];

/*RTC*/
typedef struct
{
	uint16_t x;
	uint16_t y;
	uint16_t ID_start; // The fixed icon is displayed when the variable is at this value.
	uint8_t mode;
	uint16_t Len_last;
} RTC_Info;
extern RTC_Info gRTC_Info[];
extern uint8_t RTC_num;
extern uint8_t RTC_flag;

/*text scroll*/
typedef struct
{
	uint16_t x;
	uint16_t y;
	uint16_t w;
	uint16_t h;
	uint16_t len;		  // Total pixel length of sliding content
	uint16_t cnt;		  // Record the pixel offset of scrolling
	uint8_t flag;		  // Whether to scroll
	uint16_t y_offset;	  // Record the y coordinate offset of the text content in the buffer
	uint8_t t_d;		  // Frame time interval
	uint8_t t_c;		  // Record time
	uint16_t gap;		  // Distance between tail and start
	uint8_t transparent;  // Show background color
	uint8_t scroll_en;	  // Whether to scroll
	uint8_t pixel_format; // Gray scale
	uint32_t bcolor;

	uint8_t encode;
	uint32_t zk_addr;
	uint32_t fcolor;
	//	uint8_t enbackcolor;
	uint8_t Alignment;
	uint16_t xe;
	uint16_t ye;
	uint16_t len_max;
	uint8_t *c;
	uint16_t buf_w;
	uint16_t font_w;
	uint16_t font_h;

} Scroll_Info;
extern Scroll_Info gScroll_Info[];
extern uint8_t Scroll_num;
extern uint8_t Scroll_flag;
/***********************/

/*clock*/
typedef struct
{
	uint16_t x;
	uint16_t y;
	uint16_t Image_BG;
	uint8_t L_hour;
	uint8_t S_hour;
	uint8_t W_hour;
	uint32_t Color_hour;
	uint8_t L_min;
	uint8_t S_min;
	uint8_t W_min;
	uint32_t Color_min;
	uint8_t L_sec;
	uint8_t S_sec;
	uint8_t W_sec;
	uint32_t Color_sec;

	uint16_t x_pic;
	uint16_t y_pic;
	uint16_t w_pic;
	uint16_t h_pic;
	uint32_t addr_pic;
	uint32_t len_pic;
	uint8_t flag_pic;

	uint16_t x_cen;
	uint16_t y_cen;
	uint16_t w_cen;
	uint16_t h_cen;
	uint32_t addr_cen;
	uint32_t len_cen;
	uint8_t flag_cen;
} Clock_Info;
extern Clock_Info gClock_Info[];
extern uint32_t Lay_temp;
extern uint8_t Clock_num;
extern uint8_t Clock_flag;
/***************/

/*curve*/
typedef struct
{
	uint16_t xs;
	uint16_t ys;
	uint16_t xe;
	uint16_t ye;
	uint16_t Y_Central;	 // Absolute coordinate of the middle value of the vertical axis
	uint16_t VD_Central; // Intermediate reference value of longitudinal axis
	uint32_t color;		 // Curve color
	uint16_t MUL_Y;		 // Zoom in/out��MUL_Y/256
	uint8_t channel;	 // channel
	uint8_t Dis_HOR;	 // Point spacing
	uint8_t Width;		 // Curve thickness
	uint8_t group;		 // Group number
	uint8_t dir;		 // direction
} Curve_Info;
extern Curve_Info gCurve_Info[];
extern uint8_t curve_num;
extern uint8_t curve_flag;
/**********/

/*time couonter*/
typedef struct
{
	uint16_t v_add;
	uint16_t t_add;
	uint16_t c_add;
	uint16_t x;
	uint16_t y;
	uint16_t ID_start;
	uint8_t dis_mode;
	uint8_t dir;
	uint8_t end_mode;
	uint8_t end_feedback;
	uint16_t var_addr[8];
	uint16_t var[8];
	uint16_t last_w;
} Count_Info;
extern Count_Info gCount_Info[];
typedef struct
{
	uint16_t v_add;
	uint16_t t_add;
	uint16_t c_add;
	uint8_t dir;
	uint8_t end_feedback;
	uint16_t var_addr[8];
	uint16_t var[8];
} Record_count_Info;
extern Record_count_Info gRecord_count_Info[];

/****Variable_Count display****/
extern uint8_t Var_Count_num;
extern uint8_t Var_Count_flag;
typedef struct
{
	uint16_t v_add;
	uint16_t c_add;
	uint8_t v_type;
	uint16_t V_loop;
	uint16_t V_once;
	uint16_t V_stop;
	long long Vmin;
	long long Vmax;
	uint16_t step;	
	uint16_t t_d;		// Frame time interval
	uint16_t t_c;		// Record time
	uint8_t mode;
	uint8_t feedback;
	uint16_t var_addr[8];
	uint16_t var[8];
} Var_Count_Info;
extern Var_Count_Info gVar_Count_Info[];
//void Check_Var_Count(void);
//void Variable_Count(uint8_t type, uint8_t *buff);
/************/

/***basic touch*/
typedef struct
{
	uint16_t Code; // Function code
	uint8_t len;   // length
	uint16_t Xs;   // Upper left corner coordinate
	uint16_t Ys;
	uint16_t Xe; // Lower right corner coordinate
	uint16_t Ye;
	uint16_t Keyvalue; // Key value
	uint16_t id;	   // icon id
	uint16_t press_id;
	uint16_t Next_id;
} Basci_Info;
extern Basci_Info gBasci_Info[];
extern uint8_t Basci_count;
extern uint8_t Basci_flag;
extern uint8_t Basci_num;
/*************/

/*************VarKey****************/
typedef struct
{
	uint16_t Code; // Function code
	uint8_t len;   // lenght
	uint16_t Xs;   // Upper left corner coordinate
	uint16_t Ys;
	uint16_t Xe; // Lower right corner coordinate
	uint16_t Ye;
	uint16_t id; // icon id
	uint16_t press_id;
	uint16_t Next_id;
	uint16_t var_addr[8];
	uint16_t var[8];
} VarKey_Info;
extern VarKey_Info gVarKey_Info[];
extern uint8_t VarKey_count;
extern uint8_t VarKey_flag;
extern uint8_t VarKey_num;
/************************************/

/*variable adjustment*/
typedef struct
{
	uint16_t Code; // Function code
	uint8_t len;   // lenght
	uint16_t Xs;   // Upper left corner coordinate
	uint16_t Ys;
	uint16_t Xe; // Lower right corner coordinate
	uint16_t Ye;
	uint16_t p_add;		 // variable pointer
	uint8_t p_tpye;		 // variable type
	uint8_t Adj_mode;	 // icon id
	uint8_t Return_Mode; // Threshold return
	uint16_t Adj_step;	 // Adjusting step length
	int16_t V_min;		 // lower limit
	int16_t V_max;		 // upper limit
	uint16_t V_min1;	// Lower limit
	uint16_t V_max1;	// Upper limit
	uint8_t key_mode;	 // Press mode, 0:continuous adjustment, 1:adjustment only once
	uint16_t id;
	uint16_t press_id;
} Adj_Info;
extern Adj_Info gAdj_Info[];
extern uint8_t Adj_count;
extern uint8_t Adj_flag;
extern uint8_t Adj_num;
extern uint8_t Adj_time;
extern uint8_t Adj_loop;
/***********/

/*keyboard touch*/
typedef struct
{
	uint16_t Code; // Function code
	uint8_t len;   // lenght
	uint16_t Xs;   // Upper left corner coordinate
	uint16_t Ys;
	uint16_t Xe; // Lower right corner coordinate
	uint16_t Ye;
	uint16_t Keyvalue; // Key value
	uint16_t press_id; // variable type

} Kb_Info;
extern Kb_Info gKb_Info[];
extern uint8_t Kb_count;
extern uint8_t Kb_num;
extern uint8_t Kb_flag;
extern uint8_t DioKb_flag;
extern uint8_t dot_flag;
extern uint8_t i_len;
extern uint8_t d_len;
extern uint16_t input_len;
extern uint8_t neg_flag;
extern uint16_t input_w;
extern uint8_t cur_w;
extern uint16_t cur_x;
extern uint16_t cur_y;
extern uint16_t Cusor_time;
extern uint8_t Cusor_sw;
/***********/

/*data input*/
typedef struct
{
	uint16_t Code; // Function code
	uint8_t len;   // lenght
	uint16_t Xs;   // Upper left corner coordinate
	uint16_t Ys;
	uint16_t Xe; // Lower right corner coordinate
	uint16_t Ye;
	uint16_t p_add; // variable pointer
	uint8_t p_tpye; // variable type
	uint8_t I_num;	// Bit of integer
	uint8_t D_num;	// Bit of decimal
	uint16_t kb_x;	// Keyboard display position
	uint16_t kb_y;
	uint16_t dp_x; // data display position
	uint16_t dp_y;
	uint8_t zk_id;
	uint8_t zk_w;
	uint8_t zk_h;
	uint8_t cursor_color;
	uint16_t kb_id;
	uint8_t Limite_EN; // 0xFF:Enable input range limit
	int32_t V_min;	   // lower limit
	int32_t V_max;	   // upper limit
	uint8_t Alig;	   // left justifying or right  justifying of data
	uint32_t fcolor;

} Dio_Info;
extern Dio_Info gDio_Info[];
extern uint8_t Dio_count;
extern uint8_t Dio_num;
extern uint8_t Dio_flag;
/***********/

/*********ASCII keyboard*****/
typedef struct
{
	uint16_t Code; // Function code
	uint8_t len;   // lenght
	uint16_t Xs;   // Upper left corner coordinate
	uint16_t Ys;
	uint16_t Xe; // Lower right corner coordinate
	uint16_t Ye;
	uint16_t p_add;		  // variable pointer
	uint16_t p_len;		  // variable lenght
	uint8_t scan_mode;	  // entry mode
	uint8_t zk_id;		  // font id
	uint8_t zk_w;		  // width of font
	uint8_t zk_h;		  // high of font
	uint8_t cursor_color; // color of cursor
	uint32_t fcolor;
	uint16_t dp_x; // Text display position
	uint16_t dp_y;
	uint16_t kb_id;
	uint16_t kb_x; // Keyboard display position
	uint16_t kb_y;
	uint8_t input_mode;
	uint32_t zk_addr;
} Aio_Info;
extern Aio_Info gAio_Info[];
extern uint8_t Aio_count;
extern uint8_t Aio_num;
extern uint8_t Aio_flag;
extern uint8_t AioKb_flag;
extern uint8_t CapsLock;
/*****************/

/**********GBK keyboard*****/
typedef struct
{
	uint16_t Code; // Function code
	uint8_t len;   // lenght
	uint16_t Xs;   // Upper left corner coordinate
	uint16_t Ys;
	uint16_t Xe; // Lower right corner coordinate
	uint16_t Ye;
	uint16_t p_add;		  // variable pointer
	uint16_t p_len;		  // variable lenght
	uint8_t scan_mode;	  // entry mode
	uint8_t zk_id;		  // font id
	uint8_t zk_w;		  // width of font
	uint8_t zk_h;		  // high of font
	uint8_t cursor_color; // color of cursor
	uint32_t fcolor;
	uint16_t dp_x; // Text display position
	uint16_t dp_y;
	uint32_t pycolor;
	uint8_t py_zk;
	uint8_t py_w;
	uint8_t py_h;
	uint16_t py_x; // PY display position
	uint16_t py_y;
	uint16_t cn_x;
	uint16_t cn_y;
	uint8_t spacing; // Chinese character display spacing
	uint16_t kb_id;
	uint16_t kb_x; // Keyboard display position
	uint16_t kb_y;
	uint8_t input_mode;
	uint32_t zk_addr;
	uint32_t py_addr;
} GBKio_Info;
extern GBKio_Info gGBKio_Info[];
extern uint8_t GBKio_count;
extern uint8_t GBKio_num;
extern uint8_t GBKio_flag;
extern uint8_t GBKioKb_flag;
extern uint8_t GBK_PY_length; // PY lenght
extern uint8_t GBK_CN_EN;	  // Chinese and English input method enable
extern uint8_t GBK_PY_buff[];
extern uint16_t GBK_PY_num;
extern uint8_t GBK_len;
extern uint32_t GBK_PY_addr;
extern uint8_t GBK_linenum;
/********************/

/*sliding menu*/
typedef struct
{
	uint16_t Code;	// Function code
	uint8_t len;	// lenght
	uint16_t p_add; // variable pointer
	uint16_t Xs;	// Upper left corner coordinate
	uint16_t Ys;
	uint16_t Xe; // Lower right corner coordinate
	uint16_t Ye;
	uint16_t L1;
	uint16_t L2;
	uint8_t dir;
	uint16_t frontID; // foreground picture ID
	uint16_t bgID;	  // background picture ID
	uint8_t flag;
	uint16_t V_max;
	uint16_t V_min;
	uint16_t step;
	int16_t pos; // For recording location

} SldMenu_Info;
extern SldMenu_Info gSldMenu_Info[];
extern uint8_t sldmenu_count;
extern uint8_t sldmenu_num;
extern uint8_t sldmenu_flag;
extern uint8_t SLDMfirsttouch;
extern uint16_t lastx;
extern uint16_t lasty;
extern uint16_t Sldw;
extern uint16_t Sldh;
extern uint8_t sld_mum;
/****************/

/***********popup window*****/
typedef struct
{
	uint16_t Code; // Function code
	uint8_t len;   // lenght
	uint16_t Xs;   // Upper left corner coordinate
	uint16_t Ys;
	uint16_t Xe; // Lower right corner coordinate
	uint16_t Ye;
	uint16_t Keyvalue; // Key value
	uint16_t id;	   // icon picture id
	uint16_t press_id;
	uint16_t pop_up_id;
	uint16_t pop_up_x;
	uint16_t pop_up_y;
	uint8_t function;

} Pop_up_Info;
extern Pop_up_Info gPop_up_Info[];
extern uint8_t Pop_up_count;
extern uint8_t Pop_up_flag;
extern uint8_t Pop_up_num;
extern uint8_t Pop_up_press;
extern uint16_t Pop_up_x;
extern uint16_t Pop_up_y;
extern uint16_t Pop_up_id;
/************************/

/***Gesture*/
typedef struct
{
	uint16_t Code; // Function code
	uint8_t len;   // lenght
	uint16_t page[4];
	uint16_t value[4];
} Gesture_Info;
extern Gesture_Info gGesture_Info;
extern uint8_t Gesture_press;
extern uint8_t Gesture_direction;
extern uint8_t Gesture_flag;

/*sliding bar*/
typedef struct
{
	uint16_t Code; // Function code
	uint8_t len;   // lenght
	uint16_t x1;   // background coordinate on screen
	uint16_t y1;
	uint16_t bgid; // background picture id
	uint16_t x2;   // sliding bar coordinate on screen
	uint16_t y2;
	uint16_t slideid; // sliding bar picture id
	uint16_t Xs;	  // upper left corner coordinate
	uint16_t Ys;
	uint16_t Xe; // Lower right corner coordinate
	uint16_t Ye;
	uint16_t p_add;	   // variable pointer
	uint16_t arrowid;  // touch icon id
	uint8_t direction; // sliding direction
	uint16_t lastx;
	uint16_t lasty;
	uint16_t dx;
	uint16_t dy;
	int16_t V_min; // lower limit
	int16_t V_max; // upper limit
} Slide_Info;
extern Slide_Info gSlide_Info[];
extern uint8_t Slide_count;
extern uint8_t Slide_flag;
extern uint8_t slide_first_touch;
extern uint8_t slide_num;

/*ring progress bar with touch*/
typedef struct
{
	uint16_t Code;	// Function code
	uint8_t len;	// lenght
	uint16_t p_add; // variable pointer
	uint16_t x;		// Upper left corner coordinate
	uint16_t y;
	uint16_t frontID; // foreground picture ID
	uint16_t bgID;	  // background picture ID
	uint16_t arrowid; // touch icon id
	uint16_t Sld_R;	  // sliding radius
	uint8_t tp_R;	  // touch radius
	int16_t Vmin;
	int16_t Vmax;
	uint16_t Sangle;
	uint16_t Eangle;
	uint16_t dx;
	uint16_t dy;
	uint8_t I_num;
	uint8_t D_num;
	uint8_t Alig;
	uint8_t zk_id;
	uint32_t color;
	uint16_t s_id;
	uint16_t e_id;
	uint8_t flag;

	uint16_t w1;
	uint16_t h1;
	uint8_t rm1;
	uint16_t x2;
	uint16_t y2;
	uint16_t w2;
	uint16_t h2;
	uint8_t rm2;
	uint16_t xR;
	uint16_t yR;

} RingSld_Info;
extern RingSld_Info gRingSld_Info[];
extern uint8_t RingSld_count;
extern uint8_t RingSld_firsttouch;
extern uint8_t RingSld_firstnum;
/********/

/**********pointer************/

extern uint8_t Pointer_Count_num;
extern uint8_t Pointer_Count_flag;
typedef struct
{
	uint16_t v_add;
	uint16_t base_id;
	uint16_t x;
	uint16_t y;
	uint16_t w;
	uint16_t h;
	uint16_t Pointer_x;
	uint16_t Pointer_y;
	uint16_t Sangle;
	uint16_t Eangle;
	uint16_t once_angle;
	int16_t current_angle;
	uint8_t	effect;
	uint16_t center_id;
	uint8_t	Show_Number;
	uint16_t Num_add;
	uint8_t	Num_type;
	uint16_t Num_x;
	uint16_t Num_y;
	uint16_t Num_sid;
	uint16_t Num_eid;
	uint8_t	Num_Alig;
	uint8_t leading_zero;
	uint8_t	Num_Nint;
	uint8_t	Num_Dint;
	uint8_t	mode;
	uint16_t Pointer_w;
	uint16_t Pointer_h;
	uint16_t L1;
	uint16_t L2;
	uint32_t L1_colour;
	uint32_t L2_colour;
	uint16_t Pointer_sid;
	uint16_t Pointer_eid;
	uint16_t Pointer_id;

	//Added By Jason
	uint8_t flag;
	int16_t pre_angle;
	uint16_t pre_num_x;
	uint16_t pre_num_y;
	uint16_t pre_num_w;
	uint16_t pre_num_h;
	uint16_t pre_pointer_x;
	uint16_t pre_pointer_y;
	uint16_t pre_pointer_w;
	uint16_t pre_pointer_h;
} Pointer_Info;
extern Pointer_Info gPointer_Info[];

/****Slide screen****/
typedef struct
{
	uint16_t Code;
	uint8_t len;
	uint16_t page[2];
	uint16_t value[2];
	uint16_t ys;			// Sliding area
	uint16_t ye;
} Sld_sc_Info;
extern Sld_sc_Info gSld_sc_Info;
extern uint8_t Ges_sc_flag;
extern uint8_t gFirstTouch;

#endif /* _BSP_H */
